Skip to content

lc trie: return a vector of tags#2612

Merged
alyssawilk merged 4 commits intomasterfrom
ret_vector
Feb 20, 2018
Merged

lc trie: return a vector of tags#2612
alyssawilk merged 4 commits intomasterfrom
ret_vector

Conversation

@ccaraman
Copy link
Contributor

@ccaraman ccaraman commented Feb 14, 2018

Signed-off-by: Constance Caramanolis ccaramanolis@lyft.com
Description:
The LC-Trie would only return a single tag because nested prefixes was not supported yet. To unblock nested prefixes, the getTag methods have been changed to getTags and return a vector of strings.

Risk Level: Low - change interface for class that isn't consumed yet.

Testing: Existing unit tests have been updated to expect vectors.

Docs Changes: N/A

Release Notes: N/A

Signed-off-by: Constance Caramanolis <ccaramanolis@lyft.com>
Signed-off-by: Constance Caramanolis <ccaramanolis@lyft.com>
Copy link
Contributor

@jmarantz jmarantz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drive-by comment really to help me learn what the style is supposed to be :)

* @return tag from the CIDR range that contains 'ip_address'. An empty string is returned
* if no prefix contains 'ip_address' or there is no data for the IP version of the
* ip_address.
* @return a vector of tags from the CIDR ranges and IP addresses that contains 'ip_address'. An
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the pattern here was to give the type immediately after the @param or @return keyword, e.g.

 * @return std::vector<std::string> a vector of tags ...

at least I've seen this elsewhere in the codebase. I'm not sure what script or program processes this style though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good question. I don't know what peoples preferences are these days. I'll find out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our local chatter, no one understands why we are repeating the types in the comments; and I learned they are not needed for any scripts that generate API doc currently.

IMO your form is better and we should convert everything to it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has come up a couple times. Matt commented that he started the policy out of habit, because some script (super old doxygen from 1973??) output better docs if it was included.

I think we should remove those types from all the docs. They're not providing any value, and they can get out-of-date from the actual types on the function.

If not, we should make a linter that enforces them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, i'll keep it as is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly worth a call-out on envoy-dev or maintainers - I'm so happy to kill off that rule, and hadn't realized it was "outdated" so was enforcing.

@dnoe
Copy link
Contributor

dnoe commented Feb 15, 2018

Assigned @junr03 for first maintainer pass since he reviewed the previous LC-Trie PR.

@brian-pane Can you also do a review of this here, since I see you are working with this as well? Thanks

@brian-pane
Copy link
Contributor

This change looks good to me. The one change I can think of would be to replace the std::vector return type with something like Folly's small_vector or Abseil's inlined_vector that doesn't need a heap allocation for the common case where the number of returned tags is small. But those have a drawback: the maximum expected vector size is encoded as a template parameter, and that's a detail that probably shouldn't be exposed in the trie's API.

@brian-pane
Copy link
Contributor

It looks like the TSAN test failure is due to the (unrelated) bug that was fixed by #2613, so merging master should fix it.

Signed-off-by: Constance Caramanolis <ccaramanolis@lyft.com>
@ccaraman
Copy link
Contributor Author

@brian-pane 1. I'm going to leave it as is with std::vector<> I don't want to modify the template parameter. When benchmark testing is added for LC-Trie, we can see if there are any issues with vector. 2. merged master

Copy link
Contributor

@alyssawilk alyssawilk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for splitting the refactor out from the upcoming improvements - It's nice and clean and soo much easier to review!

LGTM overall, just a few nits

* @return tag from the CIDR range that contains 'ip_address'. An empty string is returned
* if no prefix contains 'ip_address' or there is no data for the IP version of the
* ip_address.
* @return a vector of tags from the CIDR ranges and IP addresses that contains 'ip_address'. An
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly worth a call-out on envoy-dev or maintainers - I'm so happy to kill off that rule, and hadn't realized it was "outdated" so was enforcing.

if (ip_prefixes_[address].length_ == 0) {
return ip_prefixes_[address].tag_;
return_vector.push_back(ip_prefixes_[address].tag_);
// TODO(ccaraman): When nested prefixes are supported, should the /0 case be handled better.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nitty nit - either swap . for ? or make it a statement please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:) - I'll change it to a '?'.


void expectIPAndNoTag(const std::vector<std::string>& test_output) {
for (const auto& ip : test_output) {
EXPECT_EQ(0, trie_->getTags(Utility::parseInternetAddress(ip)).size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only thought on the test refactor is that if multi-vector responses are coming, you may want to refactor expectIPAndTag to actually take a vector, rather than splitting this into "one string" "empty vector" and "multi-string response" test cases. Your call if it's easier this way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to implement #2614 on top of this change by merging multiple results into a single vector. I think that will suffice for the IP tagging filter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got rid of expectIPandNoTag() and kept ExpectIPandTags(). It checks the content of the tag vector against the expected vector, empty vectors are supported too!

Signed-off-by: Constance Caramanolis <ccaramanolis@lyft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants